package com.ruoyi.project.modules.pageElement.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.modules.pageElement.domain.PageElement;
import com.ruoyi.project.modules.pageElement.service.IPageElementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 页面元素信息Controller
 * 
 * @author smallrain
 * @date 2022-05-06
 */
@Controller
@RequestMapping("/pageElement/pageElement")
public class PageElementController extends BaseController
{
    private String prefix = "pageElement/pageElement";

    @Autowired
    private IPageElementService pageElementService;

    @RequiresPermissions("pageElement:pageElement:view")
    @GetMapping()
    public String pageElement()
    {
        return prefix + "/pageElement";
    }

    /**
     * 查询页面元素信息列表
     */
    //@RequiresPermissions("pageElement:pageElement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PageElement pageElement)
    {
        startPage();
        List<PageElement> list = pageElementService.selectPageElementList(pageElement);
        return getDataTable(list);
    }

    /**
     * 导出页面元素信息列表
     */
    @RequiresPermissions("pageElement:pageElement:export")
    @Log(title = "页面元素信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PageElement pageElement)
    {
        List<PageElement> list = pageElementService.selectPageElementList(pageElement);
        ExcelUtil<PageElement> util = new ExcelUtil<PageElement>(PageElement.class);
        return util.exportExcel(list, "页面元素信息数据");
    }

    /**
     * 新增页面元素信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存页面元素信息
     */
    @RequiresPermissions("pageElement:pageElement:add")
    @Log(title = "页面元素信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PageElement pageElement)
    {
        return toAjax(pageElementService.insertPageElement(pageElement));
    }

    /**
     * 修改页面元素信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PageElement pageElement = pageElementService.selectPageElementById(id);
        mmap.put("pageElement", pageElement);
        return prefix + "/edit";
    }

    /**
     * 修改保存页面元素信息
     */
    @RequiresPermissions("pageElement:pageElement:edit")
    @Log(title = "页面元素信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PageElement pageElement)
    {
        return toAjax(pageElementService.updatePageElement(pageElement));
    }

    /**
     * 删除页面元素信息
     */
    @RequiresPermissions("pageElement:pageElement:remove")
    @Log(title = "页面元素信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pageElementService.deletePageElementByIds(ids));
    }
}
